# --coding:utf-8--
# MakeBy: LiuBoyuan
from console_conpent.select import select, cls
from effect.util.console.SuperConsole import readKey


class BaseForm:
    def formShow(self):
        ...

class SelectForm(BaseForm):
    def __init__(self,title,tips,options):
        self.title , self.tips, self.options = title,tips,options

    def formShow(self):
        """
        选择型表单
        :param args:
        :param kwargs{
            title tips options
        }
        :return:
        """
        title = self.title
        tips = self.tips
        options = self.options

        print(title,tips,options)
        selectHandler = select(title=title, options=options, tips=tips)
        selectHandler.show()
        return [selectHandler.getindex(), selectHandler.getvalue()]

class InputForm(BaseForm):
    def __init__(self, title, cls_flag=None):
        self.title = title
        self.cls = cls_flag

    def formShow(self):
        """
        输入型表单
        :param args:
        :param kwargs{
            title： input提示
        }
        :return:
        """
        title = self.title
        if self.cls:
            cls()

        value = input(title)
        print("按[z]键确认数据，按其他键重新输入")
        key : str = readKey()
        cls()
        if key.lower() != "z":
            return self.formShow()
        return value
